// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class FrequentItemSetsAggregation
{
	/// <summary>
	/// <para>Fields to analyze.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("fields")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsField> Fields { get; set; }

	/// <summary>
	/// <para>Query that filters documents from analysis.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("filter")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? Filter { get; set; }

	/// <summary>
	/// <para>The minimum size of one item set.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("minimum_set_size")]
	public int? MinimumSetSize { get; set; }

	/// <summary>
	/// <para>The minimum support of one item set.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("minimum_support")]
	public double? MinimumSupport { get; set; }

	/// <summary>
	/// <para>The number of top item sets to return.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("size")]
	public int? Size { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation(FrequentItemSetsAggregation frequentItemSetsAggregation) => Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation.FrequentItemSets(frequentItemSetsAggregation);
}

public sealed partial class FrequentItemSetsAggregationDescriptor<TDocument> : SerializableDescriptor<FrequentItemSetsAggregationDescriptor<TDocument>>
{
	internal FrequentItemSetsAggregationDescriptor(Action<FrequentItemSetsAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public FrequentItemSetsAggregationDescriptor() : base()
	{
	}

	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsField> FieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument> FieldsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument>> FieldsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument>>[] FieldsDescriptorActions { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> FilterDescriptorAction { get; set; }
	private int? MinimumSetSizeValue { get; set; }
	private double? MinimumSupportValue { get; set; }
	private int? SizeValue { get; set; }

	/// <summary>
	/// <para>Fields to analyze.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor<TDocument> Fields(ICollection<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsField> fields)
	{
		FieldsDescriptor = null;
		FieldsDescriptorAction = null;
		FieldsDescriptorActions = null;
		FieldsValue = fields;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument> descriptor)
	{
		FieldsValue = null;
		FieldsDescriptorAction = null;
		FieldsDescriptorActions = null;
		FieldsDescriptor = descriptor;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor<TDocument> Fields(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument>> configure)
	{
		FieldsValue = null;
		FieldsDescriptor = null;
		FieldsDescriptorActions = null;
		FieldsDescriptorAction = configure;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor<TDocument> Fields(params Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument>>[] configure)
	{
		FieldsValue = null;
		FieldsDescriptor = null;
		FieldsDescriptorAction = null;
		FieldsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>Query that filters documents from analysis.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor<TDocument> Filter(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>The minimum size of one item set.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor<TDocument> MinimumSetSize(int? minimumSetSize)
	{
		MinimumSetSizeValue = minimumSetSize;
		return Self;
	}

	/// <summary>
	/// <para>The minimum support of one item set.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor<TDocument> MinimumSupport(double? minimumSupport)
	{
		MinimumSupportValue = minimumSupport;
		return Self;
	}

	/// <summary>
	/// <para>The number of top item sets to return.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor<TDocument> Size(int? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FieldsDescriptor is not null)
		{
			writer.WritePropertyName("fields");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, FieldsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (FieldsDescriptorAction is not null)
		{
			writer.WritePropertyName("fields");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument>(FieldsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (FieldsDescriptorActions is not null)
		{
			writer.WritePropertyName("fields");
			writer.WriteStartArray();
			foreach (var action in FieldsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (MinimumSetSizeValue.HasValue)
		{
			writer.WritePropertyName("minimum_set_size");
			writer.WriteNumberValue(MinimumSetSizeValue.Value);
		}

		if (MinimumSupportValue.HasValue)
		{
			writer.WritePropertyName("minimum_support");
			writer.WriteNumberValue(MinimumSupportValue.Value);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class FrequentItemSetsAggregationDescriptor : SerializableDescriptor<FrequentItemSetsAggregationDescriptor>
{
	internal FrequentItemSetsAggregationDescriptor(Action<FrequentItemSetsAggregationDescriptor> configure) => configure.Invoke(this);

	public FrequentItemSetsAggregationDescriptor() : base()
	{
	}

	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsField> FieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor FieldsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor> FieldsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor>[] FieldsDescriptorActions { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> FilterDescriptorAction { get; set; }
	private int? MinimumSetSizeValue { get; set; }
	private double? MinimumSupportValue { get; set; }
	private int? SizeValue { get; set; }

	/// <summary>
	/// <para>Fields to analyze.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor Fields(ICollection<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsField> fields)
	{
		FieldsDescriptor = null;
		FieldsDescriptorAction = null;
		FieldsDescriptorActions = null;
		FieldsValue = fields;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor Fields(Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor descriptor)
	{
		FieldsValue = null;
		FieldsDescriptorAction = null;
		FieldsDescriptorActions = null;
		FieldsDescriptor = descriptor;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor Fields(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor> configure)
	{
		FieldsValue = null;
		FieldsDescriptor = null;
		FieldsDescriptorActions = null;
		FieldsDescriptorAction = configure;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor Fields(params Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor>[] configure)
	{
		FieldsValue = null;
		FieldsDescriptor = null;
		FieldsDescriptorAction = null;
		FieldsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>Query that filters documents from analysis.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public FrequentItemSetsAggregationDescriptor Filter(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>The minimum size of one item set.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor MinimumSetSize(int? minimumSetSize)
	{
		MinimumSetSizeValue = minimumSetSize;
		return Self;
	}

	/// <summary>
	/// <para>The minimum support of one item set.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor MinimumSupport(double? minimumSupport)
	{
		MinimumSupportValue = minimumSupport;
		return Self;
	}

	/// <summary>
	/// <para>The number of top item sets to return.</para>
	/// </summary>
	public FrequentItemSetsAggregationDescriptor Size(int? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FieldsDescriptor is not null)
		{
			writer.WritePropertyName("fields");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, FieldsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (FieldsDescriptorAction is not null)
		{
			writer.WritePropertyName("fields");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor(FieldsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (FieldsDescriptorActions is not null)
		{
			writer.WritePropertyName("fields");
			writer.WriteStartArray();
			foreach (var action in FieldsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.FrequentItemSetsFieldDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (MinimumSetSizeValue.HasValue)
		{
			writer.WritePropertyName("minimum_set_size");
			writer.WriteNumberValue(MinimumSetSizeValue.Value);
		}

		if (MinimumSupportValue.HasValue)
		{
			writer.WritePropertyName("minimum_support");
			writer.WriteNumberValue(MinimumSupportValue.Value);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}